package com.gqz.controller.system;

import com.gqz.domain.SysUser;
import com.gqz.query.BaseQuery;
import com.gqz.service.ISysUserService;
import com.gqz.utils.JsonResult;
import com.gqz.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询 允许空值上传
     *
     * @param query
     * @return
     */
    @GetMapping({"/{pageIndex}/{pageSize}/{keyword}", "/{pageIndex}/{pageSize}", ""})
    public JsonResult list(BaseQuery query) {
        PageList<SysUser> list = sysUserService.getAllUser(query);
        return JsonResult.ok(list);
    }

    @DeleteMapping
    public JsonResult remove(@RequestBody Long[] ids) {
        boolean result = sysUserService.batchDeleteUser(ids);
        return JsonResult.toAjax(result);
    }

    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable Long id) {
        boolean result = sysUserService.deleteUser(id);
        return JsonResult.toAjax(result);
    }

    @PutMapping
    public JsonResult edit(@RequestBody SysUser user) {
        boolean result = sysUserService.updateUser(user);
        return JsonResult.toAjax(result);
    }

    @PostMapping
    public JsonResult add(@RequestBody SysUser user) {
        boolean result = sysUserService.insertUser(user);
        return JsonResult.toAjax(result);
    }
}
